import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_base/common/dialog.dart';
import 'package:flutter_base/widgets/base/basePage.dart';
import 'package:flutter_base/widgets/commonWidgets.dart';

/// Create： Zhang 3/22/21 10:42 AM
/// 描述：弹框使用示例

class DialogPage extends BasePage {
  DialogPage() : super(title: "提示框");

  @override
  PageState createState() => Content();
}

class Content extends PageState {
  Timer? _timer;
  double _progress = 0;

  @override
  Widget? content(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: [
          commonItem(
            "成功Toast",
            icon: Icons.message,
            onClick: () {
              toastSuc(msg: "请求成功");
            },
          ),
          commonItem(
            "错误Toast",
            icon: Icons.message,
            onClick: () {
              toastError(msg: "请求失败");
            },
          ),
          commonItem(
            "loading框",
            icon: Icons.message,
            onClick: () {
              toastLoading();
              //开启一个延迟任务
              Future.delayed(
                Duration(seconds: 3),
                () {
                  return "任务结束";
                },
              ).then((value) {
                print(value);
                dismissLoading();
              });
            },
          ),
          commonItem(
            "消息Toast",
            icon: Icons.message,
            onClick: () {
              toastInfo(msg: "通知消息");
            },
          ),
          commonItem(
            "普通Toast",
            icon: Icons.message,
            onClick: () {
              toast("toast消息");
            },
          ),
          commonItem(
            "进度Toast",
            icon: Icons.message,
            onClick: () {
              _progress = 0;
              _timer?.cancel();
              _timer = Timer.periodic(
                Duration(milliseconds: 500),
                (timer) {
                  toastProgress(_progress);
                  _progress += 0.03;
                  if (_progress >= 1) {
                    _timer?.cancel();
                    dismissLoading();
                  }
                },
              );
            },
          ),
        ],
      ),
    );
  }
}
